package org.example;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class FormatReceipt {
    public static String formatReceiptContent(JSONObject expectReceipt) {
        String formatReceiptContent = "Receipt\n";
        formatReceiptContent += "-------\n";

        JSONArray productList = (JSONArray) expectReceipt.get("products");
        for(int i=0 ; i<productList.size(); i++) {
            JSONObject productItem = (JSONObject) productList.get(i);
            String name = (String) productItem.get("Name");
            String amount = (String) productItem.get("Amount");
            String price = (String) productItem.get("Price");
            String total = (String) productItem.get("Total");
            formatReceiptContent += "Name:";
            formatReceiptContent += name+",";
            formatReceiptContent += "Amount:";
            formatReceiptContent += amount+",";
            formatReceiptContent += "Price:";
            formatReceiptContent += price+",";
            formatReceiptContent += "Total:";
            formatReceiptContent += total;
            formatReceiptContent += "\n";
        }
        formatReceiptContent += "-------\n";
        String allTotalPrice = (String) expectReceipt.get("totalPrice");
        formatReceiptContent += "Total:";
        formatReceiptContent += allTotalPrice;

        return formatReceiptContent;
    }
}
